/**
 * Copyright &copy; 2012-2016 civet All rights reserved.
 */
package cn.mcsys.myadmin.modules.air.service;

import cn.mcsys.myadmin.common.persistence.Page;
import cn.mcsys.myadmin.common.service.CrudService;
import cn.mcsys.myadmin.modules.air.dao.AirSendMessageDao;
import cn.mcsys.myadmin.modules.air.entity.AirSendMessage;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 发布消息Service
 * @author leopold
 * @version 2018-08-13
 */
@Service
@Transactional(readOnly = true)
public class AirSendMessageService extends CrudService<AirSendMessageDao, AirSendMessage> {

	public AirSendMessage get(Integer id) {
		return super.get(id);
	}
	
	public List<AirSendMessage> findList(AirSendMessage airSendMessage) {
		return super.findList(airSendMessage);
	}
	
	public Page<AirSendMessage> findPage(Page<AirSendMessage> page, AirSendMessage airSendMessage) {
		return super.findPage(page, airSendMessage);
	}
	
	@Transactional(readOnly = false)
	public void save(AirSendMessage airSendMessage) {
		airSendMessage.setSendDate(new Date());
		super.save(airSendMessage);
	}
	
	@Transactional(readOnly = false)
	public void delete(AirSendMessage airSendMessage) {
		super.delete(airSendMessage);
	}

	public List<AirSendMessage> selectByAirUser() {
		return dao.selectByAirUser();
	}

	public List<AirSendMessage> getMessageByReceiverType(int type) {
		return dao.getMessageByReceiverType(type);
	}

	public void sendToWorker(String note, Integer oldPointId, Integer airRidePointId) {
		AirSendMessage workMessage = createWorkMessage(note, oldPointId);
		AirSendMessage workMessage1 = createWorkMessage(note, airRidePointId);
		dao.insert(workMessage);
		dao.insert(workMessage1);
	}

	private AirSendMessage createWorkMessage(String note,Integer pointId){
		AirSendMessage message = new AirSendMessage();
		message.setType(AirSendMessage.POINT_MESSAGE);//航展事务
		message.setContent(note);
		message.setRecevier(2);//工作人员
		message.setSender(2);//管理平台
		message.setSendDate(new Date());
		message.setPointId(pointId);
		return message;
	}

	/**
	 *
	 * @param Recevier 接收者(1观众2工作人员)
	 * @param pointId
	 * @return
	 */
	public List<AirSendMessage> selectByPointId(Integer Recevier,Integer pointId) {
		return dao.selectByPointId(Recevier,pointId);
	}
}